The following code is the pseudo code for the Data Adaptor plugin, which incorporates some of the tips and recommendations from the Data Adaptor overview topic (use this pseudo code as a starting point for a Data Adaptor plugin):
package com.oracle.determinations.interview.engine.userplugins;
import com.oracle.determinations.engine.Attribute;
import com.oracle.determinations.engine.Entity;
import com.oracle.determinations.engine.EntityInstance;
import com.oracle.determinations.engine.Relationship;
import com.oracle.determinations.engine.Rulebase;
import com.oracle.determinations.engine.Session;
import com.oracle.determinations.engine.local.LocalRulebase;
import com.oracle.determinations.engine.local.LocalSession;
import com.oracle.determinations.interview.engine.InterviewRulebase;
import com.oracle.determinations.interview.engine.InterviewSession;
import com.oracle.determinations.interview.engine.data.model.InterviewEntityInstance;
import com.oracle.determinations.interview.engine.data.model.InstanceStatus;
import com.oracle.determinations.interview.engine.data.model.InterviewUserData;
import com.oracle.determinations.interview.engine.plugins.DataAdaptorPlugin;
import com.oracle.determinations.interview.engine.plugins.InterviewSessionPlugin;
import com.oracle.determinations.interview.engine.plugins.InterviewSessionRegisterArgs;
import com.oracle.determinations.interview.engine.SecurityToken;
import com.oracle.determinations.interview.util.EngineConstants;
import com.oracle.util.plugins.Plugin;
import com.oracle.util.plugins.RegisterArgs;
public class PseudoDataAdaptor implements DataAdaptorPlugin {
//REQUIRED for Plugin implementations - "constructor with no args"
public PseudoDataAdaptor()
{
}
//REQUIRED by Plugin interface
public InterviewSessionPlugin getInstance(InterviewSessionRegisterArgs args) {
//Inspect args if needed to determine if this DataAdaptor should be used for the current InterviewSession
return null;
}
//REQUIRED by DataAdaptor interface
public boolean dataAdaptorProvidesCaseID() {
//Return true if this DataAdaptor will provide the Case ID (in save method) to use
// this means that in the UI front-end, the user cannot 'Save As' and provide a Case ID, only 'Save' to
//save the current session
//Return false if the Case ID is not provided by the Data Adaptor - e.g. by the user or another Web Determinations
//Extension
return false;
}
//REQUIRED by DataAdaptor interface
public String[] listCases(SecurityToken token, InterviewRulebase rulebase) {
//Setup connection to datasource
//Authenticate using the Security token
//Access datasource
//Retrieve list of Case ID's, format to String array
//Return String array
//If there are errors, raise an Error or unchecked Exception (e.g. implementations of RuntimeException)
return new String[0];
}
//REQUIRED by DataAdaptor interface
public InterviewUserData load(SecurityToken token, String caseID,
InterviewRulebase rulebase) {
//Setup connection to datasource
//Authenticate using the Security token
//Validate Case ID on datasource
//Create new InterviewUserData
//Get Global instance from InterviewUserData, then get Global attribute values using rulebase
//model data and datasource
//Get all Entity instances and its attribute values using rulebase model data and datasource
//Create relationships between the Entity instances retrieved using rulebase model data and
//datasource
//If there are errors, raise an Error or unchecked Exception (e.g. implementations of of RuntimeException)
return null;
}
//REQUIRED by DataAdaptor interface
public String save(SecurityToken token, String requestCaseID,
InterviewSession session) {
//Setup connection to datasource
//Authenticate using the Security token
//Start datasource transaction
//If the Case ID datasource-generated, create the record first for reference to the other
//entities/attributes/relationships
//Persist Entity instances and their attributes via rulebase model data
//Persist relationships between instances
//COMMIT datasource transaction if no errors
//If there are errors, ROLLBACK the transaction and raise an Error or unchecked Exception (e.g.
//implementations of of RuntimeException)
//Alternatively, an empty or null string can be returned to trigger the 'Save Failed' error
return null;
}
}